/***************************************************************************
 * Copyright (C) 2005 Global Biodiversity Information Facility Secretariat.
 * All Rights Reserved.
 *
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 ***************************************************************************/
package org.gbif.portal.harvest.workflow.activity.indexdata;

import org.gbif.portal.dao.IndexDataDAO;
import org.gbif.portal.util.workflow.BaseActivity;
import org.gbif.portal.util.workflow.ProcessContext;


/**
 * Sets the uncomplete index data's started and finished to be null
 * @author trobertson
 */
public class DeactivateIncompleteIndexDataActivity extends BaseActivity {
	/**
	 * The context keys
	 */
	protected String contextKeyResourceAccessPointId;
	
	/**
	 * DAOs
	 */
	protected IndexDataDAO indexDataDAO;
	
	/**
     * @see org.gbif.portal.util.workflow.BaseMapContextActivity#doExecute(org.gbif.portal.util.workflow.MapContext)
     */
    @SuppressWarnings("unchecked")
	public ProcessContext execute(ProcessContext context) throws Exception {
    	long resourceAccessPointId = (Long) context.get(getContextKeyResourceAccessPointId(), Long.class, true);
    	indexDataDAO.deactivateAllUnfinished(resourceAccessPointId);
		return context;		
	}
	/**
	 * @return Returns the contextKeyResourceAccessPointId.
	 */
	public String getContextKeyResourceAccessPointId() {
		return contextKeyResourceAccessPointId;
	}

	/**
	 * @param contextKeyResourceAccessPointId The contextKeyResourceAccessPointId to set.
	 */
	public void setContextKeyResourceAccessPointId(
			String contextKeyResourceAccessPointId) {
		this.contextKeyResourceAccessPointId = contextKeyResourceAccessPointId;
	}
	/**
	 * @return Returns the indexDataDAO.
	 */
	public IndexDataDAO getIndexDataDAO() {
		return indexDataDAO;
	}

	/**
	 * @param indexDataDAO The indexDataDAO to set.
	 */
	public void setIndexDataDAO(IndexDataDAO indexDataDAO) {
		this.indexDataDAO = indexDataDAO;
	}
}